package com.xilihui.xlh.business.activitys;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;
import android.widget.RatingBar;
import android.widget.TextView;

import com.xilihui.xlh.R;
import com.xilihui.xlh.business.entities.HistoryEntity;
import com.xilihui.xlh.business.requests.MyAppointmentRequest;
import com.xilihui.xlh.business.widget.CircleImageView;
import com.xilihui.xlh.core.app.BaseCompatActivity;
import com.xilihui.xlh.core.app.BaseEntity;
import com.xilihui.xlh.core.glide.ImageHelper;
import com.xilihui.xlh.core.http.DoTransform;
import com.xilihui.xlh.core.http.HttpSubscriber;
import com.xilihui.xlh.core.util.SPUtil;
import com.xilihui.xlh.core.util.ToastUtil;

import org.feezu.liuli.timeselector.Utils.TextUtil;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/5/25.
 */

public class EvaluationStoreActivity extends BaseCompatActivity implements View.OnClickListener {
    
    @BindView(R.id.civ_head)
    CircleImageView civ_head;
    @BindView(R.id.tv_shopName)
    TextView tv_shopName;
    @BindView(R.id.ratingBar)
    RatingBar ratingBar;
    @BindView(R.id.et_content)
    EditText et_content;
    @BindView(R.id.tv_submit)
    TextView tv_submit;
            
    String agent_id;
    String wa_id = "";
    float zan_num;
    String content;
    
    HistoryEntity.AppointBean appointBean;
    
    
    @Override
    public int getLayout() {
        return R.layout.activity_evaluation_store;
    }

    @Override
    public String initTitle() {
        return "门店评价";
    }

    @Override
    public void initUI(@Nullable Bundle savedInstanceState) {
        
        appointBean = (HistoryEntity.AppointBean) getIntent().getSerializableExtra("data");
        agent_id = appointBean.getAgent_id();
        wa_id = appointBean.getId();
        tv_shopName.setText(appointBean.getAgent().getName());
        ImageHelper.display(this,civ_head,appointBean.getAgent().getHeadimg());
        tv_submit.setOnClickListener(this);
        
    }

    @Override
    public void initData() {
         
    }


    @Override
    public void onClick(View view) {
        content = et_content.getText().toString().trim();
        if(TextUtil.isEmpty(content)){
            ToastUtil.toastShortNegative("请输入评价");
            return;
        }
        zan_num = ratingBar.getRating();
        
        if(zan_num<1){
            ToastUtil.toastShortNegative("请选择评分");
            return;
        }
        

        MyAppointmentRequest.submitComment(EvaluationStoreActivity.this,agent_id,wa_id,zan_num,
                content)
                .compose(DoTransform.<BaseEntity>applyScheduler(this,true))
                .compose(EvaluationStoreActivity.this.<BaseEntity>bindToLifecycle())
                .subscribe(new HttpSubscriber<BaseEntity>(this) {
                    @Override
                    protected void onSuccess(BaseEntity entity) {
                        ToastUtil.toastShortPositive(entity.getMsg());
                        startActivity(new Intent(EvaluationStoreActivity.this,FeedbackRecordActivity.class));
                        finish();
                    }

                    @Override
                    protected void onFail(String msg) {
                        ToastUtil.toastShortNegative(msg);
                    }
                });
        
    }
}
